#include <stdio.h>
#include <string.h>
#include "utils.h"

int bserch2(int a[],int x,int low,int high)
{
	int mid;
	
	if( low > high) 
	{	
		return -1;      //查找不成功
	}
	
	mid=(low+high)/2;
	
	if( x==a[mid] )
	{
		return mid;    //查找成功
	}
	else if(x<a[mid])
	{
		return bserch2(a,x,low,mid-1);  //在下半区查找
	}
	else
	{
		return bserch2(a,x,mid+1,high);  //在上半区查找
	}
}

/**
*
*
*
*	数值型比较.
*/
int bsearch_int(int array[], int x,int left, int right)
{
	int middle;
	
	while(left <= right)
	{
		middle = (left+right)/2;
		if (array[middle] > x)
		{
			right = middle-1;
		}
		else if(array[middle] < x)
		{
			left = middle+1;
		}
		else
		{
			return middle;
		}
	}

	return -1;
}

